package com.yanqu.road.server.cmd.activity.tonbingchannel.channel;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChannelTonBingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CTON_BING_ADD_REWARD, desc = "")
public class CTonBingAddRewardFromChannelCmd extends AbstractCommand {

    private String reward;
    private int logType1;
    private int logType2;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ChannelTonBingProto.ChannelTonBingAddRewardReqMsg reqMsg = ChannelTonBingProto.ChannelTonBingAddRewardReqMsg.parseFrom(packet.getBytes());
        reward = reqMsg.getReward();
        logType1 = reqMsg.getLogType1();
        logType2 = reqMsg.getLogType2();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (player == null) {
            log.error("userId {} add reward fail! reward = {} , log1 {} log2 {}.", packet.getPlayerId(), reward, logType1, logType2);
            return;
        }

        // 找日志类型
        eLogMoneyType log1 = eLogMoneyType.forValue(logType1);
        if (log1 == null) {
            log1 = eLogMoneyType.ChannelTonBing;
        }
        eLogMoneyType log2 = eLogMoneyType.forValue(logType2);
        if (log2 == null) {
            log2 = eLogMoneyType.ChannelTonBingAddRewardDefault;
        }

        // 加奖励
        player.getModule(CurrencyModule.class).addCurrency(reward, log1, log2);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
